from langchain_openai import ChatOpenAI
from langchain_openai import OpenAIEmbeddings
from langchain_core.output_parsers import StrOutputParser

openai_api_base = "https://api.openai-proxy.org/v1"
openai_api_key = "sk-N7HqBKMQJE8FFZ1y0m5GZielsPWFATIOSGoG82zG0k2gQI9f"

llm = ChatOpenAI(openai_api_base=openai_api_base, openai_api_key=openai_api_key)

output_parser = StrOutputParser()


def invoke_open_ai(prompt, input):
    chain = prompt | llm | output_parser
    result = chain.invoke({"input": input})
    return result


def get_open_ai_embeddings():
    return OpenAIEmbeddings(
        openai_api_base=openai_api_base, openai_api_key=openai_api_key
    )
